package com.decent.manager.system.controller;

import com.decent.common.bo.MessageBean;
import com.decent.common.bo.SimpleMessage;
import com.decent.common.entity.manager.SystemMenu;
import com.decent.common.validator.operate.Add;
import com.decent.common.validator.operate.Delete;
import com.decent.common.validator.operate.Update;
import com.decent.manager.system.dto.SystemMenuDTO;
import com.decent.manager.system.service.SystemMenuService;
import com.decent.manager.system.service.SystemRoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单管理
 *
 * @author wangyan
 **/
@RequestMapping("systemMenu")
@RestController
public class SystemMenuController {
    @Resource
    private SystemRoleService systemRoleService;

    @Resource
    private SystemMenuService systemMenuService;

    /**
     * 获取资源列表（INTERFACE级资源不需要返回）
     *
     * @param roleId 角色id
     * @return list
     */
    @RequestMapping("getMenuList")
    public List<SystemMenu> getMenuList(Long roleId) {
        return systemRoleService.getMenuList(roleId);
    }

    /**
     * 添加系统菜单
     */
    @PostMapping("/add")
    public MessageBean add(@Validated(Add.class) SystemMenuDTO sysMenuParam) {
        return systemMenuService.add(sysMenuParam);
    }

    /**
     * 删除系统菜单
     */
    @PostMapping("/delete")
    public SimpleMessage delete(@Validated(Delete.class) SystemMenuDTO sysMenuParam) {
        return systemMenuService.delete(sysMenuParam.getId());
    }

    /**
     * 编辑系统菜单
     */
    @PostMapping("/edit")
    public MessageBean edit(@Validated(Update.class) SystemMenuDTO sysMenuParam) {
        return systemMenuService.edit(sysMenuParam);
    }

}
